package com.example.kill.controller;

import com.example.kill.pojo.KillOrderInfo;
import com.example.kill.pojo.KillUser;
import com.example.kill.result.CodeMsg;
import com.example.kill.result.Result;
import com.example.kill.service.GoodsService;
import com.example.kill.service.OrderService;
import com.example.kill.vo.GoodsVo;
import com.example.kill.vo.OrderDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;
    @Autowired
    private GoodsService goodsService;

    @RequestMapping("/detail")
    @ResponseBody
    public Result<OrderDetailVo> detail(KillUser user,@RequestParam("orderId") long orderId){
        if (user == null){
            return  Result.error(CodeMsg.SESSION_ERROR) ;
        }
        KillOrderInfo order = orderService.getOrderById(orderId);
        if(order == null) {
            return Result.error(CodeMsg.ORDER_NOT_EXIST);
        }
        long goodsId = order.getGoodsId();
        GoodsVo goods = goodsService.getGoodsVoById(goodsId);
        OrderDetailVo vo = new OrderDetailVo();
        vo.setOrder(order);
        vo.setGoodsVo(goods);
        return Result.success(vo);
    }

}
